package com.vcms.utility;

/**
 * Title:        VMCS
 * Description:
 * Copyright:    Copyright (c) 2001
 * Company:      ISS
 * @author Pang Pingli
 * @version 1.0
 */

import java.io.*;
import java.util.*;

import com.vcms.exception.VMCSException;

public class Environment {

	public final static String PROP_FILE = "./properties/propFile.txt";

	//**PROPERTIES KEYS********
	//**PASSWORD************************
	public final static String PASSWORD = "password";
	
	//**STORAGE MODE********************
	public final static String STORAGE_MODE = "storageMode";
	
	//**FILE********************
	public final static String DRINK_PROP_FILE = "drinkFile";
	public final static String CASH_PROP_FILE = "cashFile";
	
	//**XML********************
	public final static String DRINK_XML_FILE = "drinkXml";
	public final static String CASH_XML_FILE = "cashXml";
	
	//**DB RELATED********************
	public final static String DATABASE_NAME = "databaseName";
	public final static String DATABASE_URL = "database_url";
	public final static String DATABASE_DRIVER = "database_driver";
	public final static String DATABASE_USERNAME = "database_username";
	public final static String DATABASE_PASSWORD = "database_password";
	
	
	public static final String STORAGE_MODE_FILE = "F";
	public static final String STORAGE_MODE_XML = "X";
	public static final String STORAGE_MODE_DATABASE = "D";

	public static Properties prop;

	public Environment() {
	}

	public void initialize() throws VMCSException {

		try {
			prop = new Properties();
			FileInputStream stream = new FileInputStream(PROP_FILE);
			prop.load(stream);
			stream.close();
		} catch (Exception e) {
			throw new VMCSException("Environment.initialize", "Error loading environment properties: " + e);
		}
	}

	public static String getPropertyValue(String key){return prop.getProperty(key);}
	
	// if you put password in the property file, the password is obtained here.
	public static String getPassword() {return Environment.getPropertyValue(PASSWORD);}
	public static String getStorageMode(){return Environment.getPropertyValue(STORAGE_MODE);}
	
	public static String getDrinkPropFile() {return Environment.getPropertyValue(DRINK_PROP_FILE);}
	public static String getCashPropFile() {return Environment.getPropertyValue(CASH_PROP_FILE);}

	public static String getDrinkXmlFile() {return Environment.getPropertyValue(DRINK_XML_FILE);}
	public static String getCashXmlFile() {return Environment.getPropertyValue(CASH_XML_FILE);}
	
	public static String getDatabaseName() {return Environment.getPropertyValue(DATABASE_NAME);}
	public static String getDatabaseUrl() {return Environment.getPropertyValue(DATABASE_URL);}
	public static String getDatabaseDriver() {return Environment.getPropertyValue(DATABASE_DRIVER);}
	public static String getDatabaseUsername() {return Environment.getPropertyValue(DATABASE_USERNAME);}
	public static String getDatabasePassword() {return Environment.getPropertyValue(DATABASE_PASSWORD);}
	
	
	public static boolean isStorageModeFile(){return Environment.STORAGE_MODE_FILE.equals(Environment.getStorageMode());}
	public static boolean isStorageModeXml(){return Environment.STORAGE_MODE_XML.equals(Environment.getStorageMode());}
	public static boolean isStorageModeDatabase(){return Environment.STORAGE_MODE_DATABASE.equals(Environment.getStorageMode());}
}